package com.example.q_kang.hhh.setting;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.q_kang.hhh.R;
import com.hjq.toast.ToastUtils;
import com.sskj.base.MVPActivity;
import com.sskj.base.api.SpConfig;
import com.sskj.base.base.App;
import com.sskj.base.utils.ClickUtil;
import com.sskj.base.utils.HideUtil;
import com.sskj.base.utils.SPUtils;
import com.sskj.base.view.ToolBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/04/10
 */
public class SetDealPwdActivity extends MVPActivity<SetDealPwdPresenter> {


    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.et_confirm_pwd)
    EditText etConfirmPwd;
    @BindView(R.id.tv_mobile)
    TextView tvMobile;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.tv_get_code)
    TextView tvGetCode;
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    @Override
    public int getLayoutId() {
        return R.layout.activity_set_dea_lpwd;
    }

    @Override
    public SetDealPwdPresenter getPresenter() {
        return new SetDealPwdPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());

    }

    @Override
    public void initData() {
        tvMobile.setText(HideUtil.getPhoneHide((String) SPUtils.get(App.INSTANCE, SpConfig.MOBILE, "")));
        ClickUtil.click(300, tvGetCode, view -> mPresenter.sendCode((String) SPUtils.get(App.INSTANCE, SpConfig.MOBILE, "")));
        ClickUtil.click(300, btnSubmit, new ClickUtil.Click() {
            @Override
            public void click(View view) {
                if (TextUtils.isEmpty(etPwd.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaSetDealPwdActivity3));
                    return;
                }
                if (!etPwd.getText().toString().equals(etConfirmPwd.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaSetDealPwdActivity4));
                    return;
                }
                if (TextUtils.isEmpty(etCode.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaSetDealPwdActivity5));
                    return;
                }
                showLoading();
                mPresenter.changePayPwd(etPwd.getText().toString(), etCode.getText().toString());

            }
        });

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, SetDealPwdActivity.class);
        context.startActivity(intent);
    }

    public void sendCodeSuccess() {
        startTimeDown(tvGetCode);
    }

}
